using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace FastFoodToNight.Models.Mapping
{
    public class SanPhamMap : EntityTypeConfiguration<SanPham>
    {
        public SanPhamMap()
        {
            // Primary Key
            this.HasKey(t => t.masanpham);

            // Properties
            this.Property(t => t.tensanpham)
                .HasMaxLength(100);

            // Table & Column Mappings
            this.ToTable("SanPham");
            this.Property(t => t.masanpham).HasColumnName("masanpham");
            this.Property(t => t.tensanpham).HasColumnName("tensanpham");
            this.Property(t => t.mota).HasColumnName("mota");
            this.Property(t => t.dongia).HasColumnName("dongia");
            this.Property(t => t.madanhmuc).HasColumnName("madanhmuc");

            // Relationships
            this.HasOptional(t => t.DanhMucSanPham)
                .WithMany(t => t.SanPhams)
                .HasForeignKey(d => d.madanhmuc);

        }
    }
}
